package com.xxr.mom.ci.charging.interworking.listener;

import com.xxr.mom.ci.charging.interworking.dto.InterworkingConfigDto;
import com.xxr.mom.ci.charging.interworking.dto.RePushDto;
import com.xxr.mom.ci.charging.interworking.listener.handler.RePushHandler;
import com.xxr.mom.ci.common.log.LogTrace;
import com.xxr.mom.ci.common.util.Constant;
import com.xxr.mom.ci.common.util.JsonUtil;
import lombok.extern.log4j.Log4j2;
import org.apache.logging.log4j.ThreadContext;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 重推处理
 */
@Log4j2
@Component
@RocketMQMessageListener(topic = Constant.MqTopic.RE_PUSH, consumerGroup = Constant.MqGroup.CI_PRODUCER_GROUP)
public class RocketMQRePushListener implements RocketMQListener<RePushDto> {

    @Autowired
    private RePushHandler rePushHandler;

    @Override
    public void onMessage(RePushDto message) {
        log.info("收到MQ消息：{}", JsonUtil.toJSONString(message));
        String logTraceId = message.getLogTraceId();
        Object r = message.getData();
        InterworkingConfigDto configDto = message.getConfigDto();
        ThreadContext.put(LogTrace.TRACE_ID, logTraceId);
        rePushHandler.send(r, configDto);
    }
}
